﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;
using WinFormsApp1.TongShiWei.PigData;

namespace WinFormsApp1.TongShiWei.segmentationData
{
    public partial class ScaleData_ : UIForm
    {
        int depotId = 0;
        public ScaleData_(int DepotId = 0)
        {
            InitializeComponent();
            //显示磅秤表信息
            ShowScaleData();
            depotId = DepotId;
        }
        public async void ShowScaleData()
        {
            //localhost:5106/api/Tsw/ShowScaleData
            var res = await HttpClientHelper.RequestUrl<_ScaleData, ApiResult<List<_ScaleData>>>(URLCommon.Url2, "/TSW/ShowScaleData", HttpClientHelper.MethodType.GET);
            if (res.Code > 0)
            {
                res.Data = res.Data.Where(x => x.BindDepotId == depotId).ToList();
                int x = 10; int y = 70; int i = 1;
                foreach (var item in res.Data)
                {
                    Button button = new Button()
                    {
                        Location = new Point(x, y),
                        Size = new System.Drawing.Size(150, 80),
                        AutoSize = true,
                        Name = item.ScaleTypeId.ToString(),
                        TextAlign = ContentAlignment.MiddleCenter,
                        BackColor = Color.White,
                    };
                    button.Text = item.ScaleName;
                    button.Click += new System.EventHandler(Button_Cliek);
                    this.Controls.Add(button);
                    if (i == 5)
                    {
                        x = 10;
                        y += 90;
                        i = 1;
                    }
                    else
                    {
                        x += 165;
                        i++;
                    }
                }
            }
        }
        public event Action<int> GetScaleIdData_;
        private void Button_Cliek(object sender, EventArgs e)
        {
            var data = sender as Button;
            var ScaleName = Convert.ToInt32(data.Name);
            GetScaleIdData_?.Invoke(ScaleName);
            this.Hide();

        }
        public class _ScaleData
        {
            /// <summary>
            /// 磅秤表ID
            /// </summary>
            public int ScaleId { get; set; }
            /// <summary>
            /// 磅秤类型ID
            /// </summary>
            public int ScaleTypeId { get; set; }
            /// <summary>
            /// 磅秤名称
            /// </summary>
            public string ScaleName { get; set; } = string.Empty;
            /// <summary>
            /// 使用状态
            /// </summary>
            public bool IsScaleState { get; set; }
            /// <summary>
            /// 皮重扣减(公斤)
            /// </summary>
            public int TareNum { get; set; }
            /// <summary>
            /// 皮重按件累加
            /// </summary>
            public bool IsTareAdd { get; set; } = false;
            /// <summary>
            /// 绑定仓库
            /// </summary>
            public int BindDepotId { get; set; }
            /// <summary>
            /// 自动出/入库
            /// </summary>
            public bool IsGoDepot { get; set; } = false;
            /// <summary>
            /// 商品代号名称
            /// </summary>
            public string UPCDataName { get; set; } = string.Empty;
            /// <summary>
            /// 操作人
            /// </summary>
            public string OperatorName { get; set; } = string.Empty;
            /// <summary>
            /// 创建时间
            /// </summary>
            public DateTime ScaleCreateTime { get; set; } = DateTime.Now;
            /// <summary>
            /// 最后修改人
            /// </summary>
            public string Modifier { get; set; } = string.Empty;
            /// <summary>
            /// 最后修改时间
            /// </summary>
            public DateTime RevempTime { get; set; } = DateTime.Now;
            /// <summary>
            /// 是否删除{false:不删除,true:删除}
            /// </summary>
            public bool IsScaleDelete { get; set; } = false;
            /// <summary>
            /// 是否禁用{false:不禁用,true:禁用}
            /// </summary>
            public bool IsScaleDisable { get; set; } = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
        //关闭页面
        private void button1_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
